
#pragma once

#include <vector>
#include <algorithm>
#include <string>
#include <iostream>
#include <fstream>
#include <boost/dynamic_bitset.hpp>

using namespace std;

class BloomFilter
{
public:
	BloomFilter(unsigned int expectedFields, double desiredFalseProbability = 0.1);
	bool Insert(const string& inputLine);
	bool IsPresent(const string& key);
	void LoadFromString(const string& inputLine);
	string ToString(void);	
	void WriteToFile(ofstream& outputFile);
private:
	unsigned int *GetIndices(vector<unsigned char>& inBytes);
	unsigned int *GetBloomIndices(vector<unsigned char>& inBytes, int numberOfIndices);
	bool Insert(vector<unsigned char>& inBytes);
	bool Insert(unsigned char *inBytes, int length);
	bool IsPresent(vector<unsigned char>& inBytes);
	bool IsPresent(unsigned char* inBytes, int length);
	unsigned int *GetMD5Indices(unsigned char* input, int size);
	unsigned char* MD5Bytes(unsigned char* input, unsigned int inputSize);
private:
	boost::dynamic_bitset<> bloomBits;
	unsigned int NumberOfIndices;
};

